package com.hmyd.hmyd_android.dialog;

import com.hmyd.hmyd_android.R;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

public class NormalDialog extends Dialog implements
		android.view.View.OnClickListener {

	private TextView title;
	private TextView msg;

	private View mClosed;
	private Button ok;
	private Button cancle;

	private String titleStr;
	private String msgStr;
	private String okStr;
	private String cancleStr;

	private NormalDialogListener mOnclickListener;

	public NormalDialog(Context context) {
		super(context);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

	}

	public NormalDialog(Context context, int theme,
			NormalDialogListener onclickListener, String title, String msg,
			String okstring,String cancleString) {
		super(context, theme);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		mOnclickListener = onclickListener;

		titleStr = title;
		msgStr = msg;
		okStr = okstring;
		cancleStr = cancleString;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_normal);

		mClosed = findViewById(R.id.closed);
		mClosed.setOnClickListener(this);

		title = (TextView) findViewById(R.id.title);
		msg = (TextView) findViewById(R.id.msg);

		if (!TextUtils.isEmpty(titleStr)) {
			title.setText(titleStr);
		}

		if (!TextUtils.isEmpty(msgStr)) {
			msg.setText(msgStr);
		}

		ok = (Button) findViewById(R.id.ok);
		ok.setOnClickListener(this);

		cancle = (Button) findViewById(R.id.cancle);
		cancle.setOnClickListener(this);

		if (!TextUtils.isEmpty(okStr)) {
			ok.setText(okStr);
		}
		
		if (!TextUtils.isEmpty(cancleStr)) {
			cancle.setText(cancleStr);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.closed:
			mOnclickListener.closed();
			cancel();
			break;
		case R.id.ok:
			mOnclickListener.ok();
			cancel();
			break;
		case R.id.cancle:
			mOnclickListener.cancle();
			cancel();

			break;
		default:
			break;
		}

	}

}
